package net.maku.events.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import net.maku.events.query.UserPointsRecordsQuery;
import net.maku.events.service.UserPointsRecordsService;
import net.maku.events.vo.UserPointsRecordsVO;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.common.utils.Result;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 用户参与的活动
 *
 * @author 阿沐 babamu@126.com
 * @since 1.0.0 2025-03-22
 */
@RestController
@RequestMapping("events/user_points_records")
@Tag(name = "用户积分记录")
@AllArgsConstructor
public class UserPointsRecordsController {
    private final UserPointsRecordsService userPointsRecordsService;

    @GetMapping("page")
    @Operation(summary = "分页")
    @PreAuthorize("hasAuthority('events:user_join_activity:page')")
    public Result<PageResult<UserPointsRecordsVO>> page(@ParameterObject @Valid UserPointsRecordsQuery query) {
        PageResult<UserPointsRecordsVO> page = userPointsRecordsService.page(query);
        return Result.ok(page);
    }

    @GetMapping("user/point")
    @Operation(summary = "查看用户积分的消减")
    @PreAuthorize("hasAuthority('events:user_join_activity:page')")
    public Result<Map<String, Double>> userPoint() {
        return Result.ok(userPointsRecordsService.userPoint());
    }
}